import { getPayVip, payVip } from '@/api/my'
export default {
	data() {
		return {
			id: '',
			orderInfo: {},
			chooseId: 2,
			payList: [
				{ name: '微信支付', id: 2, icon: '/static/img/my/weixin.png', iconColor: '#1fbe2a' },
				{ name: '支付宝支付', id: 1, icon: '/static/img/my/zhifubao.png', iconColor: '#01a9f2' }
			],
			collegeId: ''
		};
	},
	onLoad(e) {
		this.id = e.id
		this.collegeId = e.collegeId
		this.getOrderInfo()
	},
	methods: {
		changePay(item) {
			if (this.chooseId != item.id) {
				this.chooseId = item.id
			}
		},
		getOrderInfo() {
			getPayVip({ id: this.id }).then(({ code, data, msg }) => {
				if (code == 1) {
					this.orderInfo = data
				} else {
					this.$used.appBack(msg)
				}
			})
		},
		confirm() {
			const platform = uni.getSystemInfoSync().platform
			let params = {
				id: this.id,
				pay_type: this.chooseId,
				rLoading: true,
				source: 'phone',
				system: platform == 'ios' ? 2 : 1
			}
			payVip(params).then(({ code, data, msg }) => {
				if (code == 1) {
					uni.requestPayment({
						provider: this.chooseId == 1 ? "alipay" : "wxpay",
						orderInfo: data, //微信、支付宝订单数据
						success: (res) => {
							console.log(res);
							uni.redirectTo({
								url: '/pages/my/vip/payResult?payStatus=1' + '&collegeId=' + this.collegeId
							})
						},
						fail: (err) => {
							console.log(err);
							uni.redirectTo({
								url: '/pages/my/vip/payResult'
							})
						},
						complete:(res)=>{
							console.log(res,'complete');
						}
					});
				} else {
					this.$used.msg(msg)
				}
			})
		}
	}
}